﻿<!-- announcementAdd -->
<?
global $DB, $sess, $sPOST, $sGET;
include_once "settings.inc.php";

if(isset($_POST))
{
	$sql = "SELECT * FROM " . _MODULE_NAME . " WHERE id=".$sGET['id'];
	$row = $DB->fetchArray($sql);
	if(!is_array($row[0]))
		git("?"._MODULE_NAME.".list");

	if($row[0]['picture'] == "")
		$pictureContent = "<input type=\"file\" name=\"picture\" id=\"picture\" />";
	else
		$pictureContent = "<a href=\"../pictures/" . _MODULE_NAME . "/bigs/" . $row[0]['picture'] . "\" class=\"galeri\"><img src=\"../pictures/" . _MODULE_NAME . "/thumbs/" . $row[0]['picture'] . "\" /></a> <img src=\"images/iconDelete.png\" id=\"" . $row[0]['id'] . "\" class=\"pictureDelete\" title=\"Sil\" />";
}
?>
<style>
	label		{	font-family:Tahoma; font-size:12px; font-weight:bold; text-align:right;	}
	textarea 	{	position:relative; min-height:60px; background:#fff;	}
	.etiket		{	width:150px; min-height:30px; line-height:30px;	}
	.pictureDelete {	cursor: pointer;}
	#pictureContainer > a > img {	border:3px solid #555;}
</style>

<script>
	$(function(){
		$('.pictureDelete').bind("click",function(event){
			if(confirm("Bu ürüne ait resmi silmek istediğinizden emin misiniz?"))
			{
				var id = $(event.target).attr("id");
				var result = toPost("?<?=_MODULE_NAME;?>.otherProcess","action=1&process=deletePicture&id="+id);
				switch(result)
				{
					case "OK":
						$('#pictureContainer').html("<input type=\"file\" name=\"picture\" id=\"picture\" />");
					break;

					case "ERROR":
						alert("Resim bir hatadan dolayı silinemedi.");
					break;

					default:
						alert(result);
					break;
				}
			}
		});
	});
</script>

<h2>ÜRÜN GÜNCELLE</h2>
<form method="post" action="?<?=_MODULE_NAME?>.editProcess" method="POST" enctype="multipart/form-data" >
	<fieldset>
		<!-- <legend>Duyuru Ekleme</legend> -->
		<input type="hidden" name="id" id="id" value="<?=$row[0]['id']?>" />
		<table cellpadding="0" cellspacing="3" border="0" style="width:100%;">
			<tr>
				<td class="right etiket"><label for="category_namex">Ürün Kategorisi : </label></td>
				<td>
					<select name="category_id" id="category_id">
						<?
							function subCategoryList($parentId, $symbol, $selected)
							{
								global $DB;
								$sym.=$symbol;
								$sql="SELECT * FROM "._MODULE_NAME."Category WHERE parent=$parentId ORDER BY row ASC";
								$categorys = $DB->fetchArray($sql);
								if(is_array($categorys[0]))
								{
									foreach($categorys as $cat)
									{
										if($selected == $cat['id'])
										echo '<option value="'.$cat['id'].'" selected="selected">'.$sym.$cat['category_name'].'</option>';
										else
										echo '<option value="'.$cat['id'].'">'.$sym.$cat['category_name'].'</option>';
										subCategoryList($cat['id'],$sym." &rarr; ",$selected);
									}
								}
							}
							subCategoryList(0," ",$row[0]['id']);
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td class="right etiket"><label for="product_namex">Ürün Adı: </label></td>
				<td><input class="mf" name="product_name" id="product_namex" type="text" value="<?=$row[0]['product_name']?>" /></td>
			</tr>
			<tr>
				<td class="right etiket"><label for="materialsx">Malzeme : </label></td>
				<td><textarea name="materials" id="materialsx"><?=$row[0]['materials']?></textarea></td>
			</tr>
			<tr>
				<td class="right etiket"><label for="quantityx">Miktar : </label></td>
				<td><input class="mf" name="quantity" id="quantityx" type="text" value="<?=$row[0]['quantity']?>" /></td>
			</tr>
			<tr>
				<td class="right etiket"><label for="contentx">Açıklama : </label></td>
				<td><textarea name="content" id="contentx"><?=$row[0]['content']?></textarea></td>
			</tr>
			<tr>
				<td class="right etiket"><label for="picture">Resim: </label></td>
				<td id="pictureContainer"><?=$pictureContent ?></td>
			</tr>
			<tr>
				<td class="etiket">&nbsp;</td>
				<td class="left">
					<input class="button" type="submit" value="Güncelle" />
					<input class="button geri" type="button" value="Geri" />
				</td>
			</tr>
		</table>
	</fieldset>
</form>
<!-- /announcementAdd -->		